package com.baosu.controller.back;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baosu.domain.ArticleDto;
import com.baosu.domain.Result;
import com.baosu.service.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/article")
@Api(tags = "文章接口-后台")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @PostMapping
    @ApiOperation(value = "添加文章")
    public Result add(@RequestBody ArticleDto articleDto){
        return articleService.add(articleDto);
    }

    @DeleteMapping
    @ApiOperation(value = "删除文章")
    public Result deleteArticleAndTag(@RequestParam List<Long> ids){
        return articleService.deleteArticleAndTag(ids);
    }

    @PutMapping
    @ApiOperation(value = "修改文章")
    public Result updateArticle(@RequestBody ArticleDto articleDto){
        return articleService.updateArticle(articleDto);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据ID查询文章详情")
    public Result selectById(@PathVariable("id") Long id){
        return articleService.selectById(id);
    }

    @GetMapping
    @ApiOperation(value = "分页列表,模糊搜索")
    public Result list(String query, int pagenum, int pagesize){
        return articleService.pageTagList(query,pagenum,pagesize);
    }

    @PutMapping("/updateCount/{id}")
    @ApiOperation(value = "阅读全文,浏览量加1")
    public Result updateCount(@PathVariable Long id){
        return articleService.updateCount(id);
    }


}
